package cnsukidayo.com.gitee.controller.user;

import cnsukidayo.com.gitee.model.params.AddPetLogParam;
import cnsukidayo.com.gitee.model.params.LoginParam;
import cnsukidayo.com.gitee.model.params.PurchaseSuppliesParam;
import cnsukidayo.com.gitee.model.pojo.PetShelter;
import cnsukidayo.com.gitee.model.support.BaseResponse;
import cnsukidayo.com.gitee.model.vo.PetShelterVO;
import cnsukidayo.com.gitee.service.PetShelterService;
import cnsukidayo.com.gitee.utils.UserContextUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author sukidayo
 * @date: 2023/3/13 14:23
 */
@RestController
@RequestMapping("/user/petshelter")
public class PetShelterController {

    private final PetShelterService petShelterService;

    public PetShelterController(PetShelterService petShelterService) {
        this.petShelterService = petShelterService;
    }

    @ApiOperation("宠物收留所用户登陆")
    @PostMapping(value = "login")
    public BaseResponse<Integer> login(@RequestBody @Validated LoginParam loginParam, HttpServletResponse httpServletResponse) {
        return BaseResponse.ok(petShelterService.login(loginParam, httpServletResponse));
    }

    @ApiOperation("根据token获取当前用户信息")
    @GetMapping("getPetStoreInfo")
    public PetShelterVO getPetShelterInfo(@RequestParam Integer id) {
        PetShelter petStore = petShelterService.getPetShelterInfo(id);
        PetShelterVO petShelterVO = new PetShelterVO();
        BeanUtils.copyProperties(petStore, petShelterVO);
        return petShelterVO;
    }

    @ApiOperation("添加宠物日志")
    @PostMapping("addPetLog")
    public void addPetLog(@RequestBody @Validated AddPetLogParam addPetLogParam, HttpServletRequest httpServletRequest) {
        petShelterService.addPetLog(UserContextUtils.getToken(httpServletRequest), addPetLogParam);
    }

    @ApiOperation("收留所使用资金")
    @PostMapping("purchaseSupplies")
    public void purchaseSupplies(@RequestBody @Validated PurchaseSuppliesParam purchaseSuppliesParam, HttpServletRequest httpServletRequest) {
        petShelterService.purchaseSupplies(UserContextUtils.getToken(httpServletRequest), purchaseSuppliesParam);
    }


}
